<extend name="Index:info"/>
<block name="title">新闻分类</block>
<block name="body">
  <style>
    #edit,#del{display:inline-block;}
    #edit:hover{
      cursor:pointer
    }
  </style>
<div class="panel admin-panel">
  <div class="panel-head"><strong class="icon-reorder"> 内容列表</strong></div>
  <div class="padding border-bottom">
    <button type="button" class="button border-yellow" onclick="window.location.href='#add'"><span class="icon-plus-square-o"></span> 添加分类</button>
  </div>
  <table class="table table-hover text-center">
    <tr>
      <th width="5%">ID</th>
      <th width="15%">一级分类</th>
      <th width="15%">上级分类</th>
      <th width="10%">排序</th>
      <th width="10%">操作</th>
    </tr>
    <volist name="category" id="val">
      <tr>
        <td>{$val.category_id}</td>
        <td>{$val.category_name}</td>
        <td>{$val.parent_id}</td>
        <td>{$val.sort}</td>
        <td>
          <div class="button-group">
            <div id="edit">
            <a class="button border-main" onclick='return alt("{$val.id}")'>
              <span class="icon-edit"></span> 修改
            </a></div>
            <div id="del">
            <a class="button border-red" href="javascript:void(0)" onclick='return del("{$val.id}")'>
              <span class="icon-trash-o"></span> 删除
            </a></div>
          </div>
        </td>
      </tr>
    </volist>
  </table>
</div>

<div class="panel admin-panel margin-top">
  <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>添加内容</strong></div>
  <div class="body-content">
    <form method="post" class="form-x" action="">
      <div class="form-group">
        <div class="label">
          <label>上级分类：</label>
        </div>
        <div class="field">
          <select name="parent_id" class="input w50">
            <option value="0">无</option>
            <volist name="parent_category" id="val">
              <option value="{$val.category_id}">{$val.category_name}</option>
            </volist>

          </select>
          <div class="tips">不选择上级分类默认为一级分类</div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>分类标题：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" name="category_name" />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>批量添加：</label>
        </div>
        <div class="field">
          <textarea type="text" class="input w50" name="tits" style="height:150px;" placeholder="多个分类标题请转行"></textarea>
          <div class="tips">多个分类标题请转行</div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>分类关键字：</label>
        </div>
        <div class="field">
          <input type="text" class="input" name="category_keywords" />
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>排序：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" name="sort" value=""  data-validate="number:排序必须为数字" />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="submit">提交</button>
        </div>
      </div>
    </form>
  </div>
</div>
  <div class="panel admin-panel margin-top" id="alter" style="display:none;">
    <div class="panel-head"><strong><span class="icon-pencil-square-o"></span>修改内容</strong></div>
    <div class="body-content">
      <form method="post" class="form-x" action="{:U('news/ajax')}">
        <div class="form-group">
          <div class="label">
            <label>上级分类：</label>
          </div>
          <div class="field">
            <select name="parent_id" class="input w50">
              <option value="0">无</option>
              <volist name="parent_category" id="val">
                <option value="{$val.category_id}">{$val.category_name}</option>
              </volist>

            </select>
            <div class="tips">不选择上级分类默认为一级分类</div>
          </div>
        </div>
        <div class="form-group">
          <div class="label">
            <label>分类标题：</label>
          </div>
          <div class="field">
            <input type="text" class="input w50" name="category_name" value=""/>
            <div class="tips"></div>
          </div>
        </div>
        <div class="form-group">
          <div class="label">
            <label>批量添加：</label>
          </div>
          <div class="field">
            <textarea type="text" class="input w50" name="tits" style="height:150px;" placeholder="多个分类标题请转行"></textarea>
            <div class="tips">多个分类标题请转行</div>
          </div>
        </div>
        <div class="form-group">
          <div class="label">
            <label>分类关键字：</label>
          </div>
          <div class="field">
            <input type="text" class="input" name="category_keywords" />
          </div>
        </div>
        <div class="form-group">
          <div class="label">
            <label>排序：</label>
          </div>
          <div class="field">
            <input type="text" class="input w50" name="sort" value=""  data-validate="number:排序必须为数字" />
            <div class="tips"></div>
          </div>
        </div>
        <div class="form-group">
          <div class="label">
            <label></label>
          </div>
          <div class="field">
            <input type="hidden" name="category_id" value="">
            <button class="button bg-main icon-check-square-o" type="submit">提交</button>
          </div>
        </div>
      </form>
    </div>
  </div>
  <script type="text/javascript">
    /* 修改数据 */
    $('div[id=edit]').click(function(){
      $("div[id=alter]").css("display","block");
      window.location.href='#alter';
    });
    function alt(id){
      console.log(id);
      var $id = id;
      $.ajax({
        async : false,
        url:"{:U('news/ajax')}",
        type :'get',
        data:'id='+$id,
        dataType: "json",
        success:function(data){
          $('#alter').find('input[name=category_id]').val(data.id);
          $('#alter').find('input[name=category_name]').val(data.category_name);
          $('#alter').find('input[name=category_keywords]').val(data.category_keywords);
          $('#alter').find('input[name=sort]').val(data.sort);

        }
      });
    }
    /* 删除数据 */
    function del(id){

      //console.log(id);
      //console.log(mid);
      var del = confirm("您确定要删除吗?");
      var $id = id;
      if(del == true){
        $.ajax({
          async : false,
          url:"{:U('news/del')}",
          type :'get',
          data:'id='+$id,
          dataType: "json",
          success:function(data){
            window.location.reload();
          }
        });

      }
    }

  </script>
</block>
